package ginservice
import (
	"github.com/gin-gonic/gin"
	"net/http"
	"domain"
	"redisService"
)
var dataSource *domain.RunningOrder

var responsesucced = map[string]interface{}{
	"retcode":100,
	"retmsg":"succeed",
}
var responsefailed =map[string]interface{}{
	"retcode":200,
	"retmsg":"failed",
}

func NewGin(runningorder *domain.RunningOrder) *gin.Engine {
	dataSource = runningorder
//	gin.SetMode(gin.ReleaseMode)
	r := gin.Default()
	r.GET("/avgtime", getAvgTime)
	//match avgtime/00230029
	return r
}

func getAvgTime(c *gin.Context) {
//	resid := c.Param("resid");
//	fmt.Println(resid)
	content,err := redisService.GetResAvgtime();
	if err != nil {
		panic(err)
		c.JSON(http.StatusOK,gin.H{
			"retcode":200,
			"retmsg":"failed",
		})
	}else {
		c.JSON(http.StatusOK, gin.H{
			"retcode":100,
			"retmsg":"succeed",
			"content":content,
		})
	}
}
